from scipy import signal
import numpy as np
class EnvironmentRecorder:
    """案发现场监控系统：记录环境激励'作案痕迹'"""

    def __init__(self, duration=60, sr=1000):
        """
        参数说明：
        duration : 录制时长(秒) -> 监控录像持续时间
        sr : 采样率(Hz) -> 相当于视频帧率
        """
        self.buffer = np.zeros(int(duration * sr))

    def record(self, excitation):
        """记录环境激励数据：如风振、车流等'作案过程'"""
        self.buffer = excitation  # 简化的实现

    def analyze_environment(self):
        """环境特征分析：生成声纹图谱"""
        f, t, Sxx = signal.stft(self.buffer, fs=1000)
        return {'freq': f, 'time': t, 'spectrogram': Sxx}